package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/6.
 */
@HttpInlet(Conn.USERCOLLECT_GET)
public class MyCollectionGet extends BaseAsyGet<MyCollectionGet.MyCollectionEntity> {

    public String user_id, type;

    public MyCollectionGet(AsyCallBack<MyCollectionEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected MyCollectionEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            MyCollectionEntity myCollectionEntity = new MyCollectionEntity();

            JSONArray array = object.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                JSONObject collectionObject = array.optJSONObject(i);

                MyCollection myCollection = new MyCollection();

                GoodsInfo info = new GoodsInfo();

                JSONObject goodsInfoObject = collectionObject.optJSONObject("info");

                if(!goodsInfoObject.isNull("status")){

                    myCollection.id = collectionObject.optString("id");
                    myCollection.user_id = collectionObject.optString("user_id");
                    myCollection.aid = collectionObject.optString("aid");
                    myCollection.type = collectionObject.optString("type");
                    myCollection.posttime = collectionObject.optString("posttime");

                    info.title = goodsInfoObject.optString("title");
                    info.picurl = Conn.IMAGE_BANNER_URL + goodsInfoObject.optString("picurl");
                    info.title = goodsInfoObject.optString("title");
                    info.placeid = goodsInfoObject.optString("placeid");
                    info.is_seat = goodsInfoObject.optString("is_seat");
                    info.price_low = goodsInfoObject.optString("price_low");
                    info.price_high = goodsInfoObject.optString("price_high");
                    info.status = goodsInfoObject.optString("status");
                    info.place_name = goodsInfoObject.optString("place_name");

                    myCollection.info = info;

                    myCollectionEntity.myCollectionList.add(myCollection);

                }

            }

            return myCollectionEntity;

        }

        return null;

    }

    public class MyCollectionEntity {

        public List<MyCollection> myCollectionList = new ArrayList<>();

    }

    public class MyCollection {

        public String id, user_id, aid, type, posttime;

        public GoodsInfo info;

    }

    public class GoodsInfo {
        public String title, picurl, placeid, is_seat, price_low, price_high, status, place_name;
    }
}
